package com.charging.controller.user;


import com.charging.entity.Announcement;
import com.charging.entity.ChargingPile;
import com.charging.entity.User;
import com.charging.service.AnnouncementService;
import com.charging.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/user/announcement")
public class AnnouncementController {

    @Resource
    private AnnouncementService announcementService;

    @Resource
    private UserService userService;

    @GetMapping("/list")
    public String list(Model model, Long id){
        User user = userService.getUserById(id);
        model.addAttribute("user",user);
        List<Announcement> announcementList = announcementService.getAllValidAnnouncements();
        model.addAttribute("announcementList",announcementList);
        return "user/announcement/list";
    }

    @GetMapping("/detail/{id}")
    public String detail(@PathVariable Long id, Model model) {
        Announcement announcement = announcementService.getAnnouncementById(id);
        model.addAttribute("announcement",announcement);
        return "user/announcement/detail";
    }
}
